package com.pie4cloud.pie.job.biz.gather.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pie4cloud.pie.common.core.util.R;
import com.pie4cloud.pie.common.log.annotation.SysLog;
import com.pie4cloud.pie.job.api.entity.ConfigMetadata;
import com.pie4cloud.pie.job.biz.gather.service.ConfigMetadataService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author feilei
 * @date 2022-01-10 00:54:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/configmetadata" )
@Api(value = "configmetadata", tags = "管理")
public class ConfigMetadataController {

    private final ConfigMetadataService configMetadataService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param configMetadata 
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('gather_configmetadata_get')" )
    public R getConfigMetadataPage(Page page, ConfigMetadata configMetadata) {
        return R.ok(configMetadataService.page(page, Wrappers.query(configMetadata)));
    }


    /**
     * 通过id查询
     * @param metadataId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{metadataId}" )
    @PreAuthorize("@pms.hasPermission('gather_configmetadata_get')" )
    public R getById(@PathVariable("metadataId" ) Long metadataId) {
        return R.ok(configMetadataService.getById(metadataId));
    }

    /**
     * 新增
     * @param configMetadata 
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('gather_configmetadata_add')" )
    public R save(@RequestBody ConfigMetadata configMetadata) {
        return R.ok(configMetadataService.save(configMetadata));
    }

    /**
     * 修改
     * @param configMetadata 
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('gather_configmetadata_edit')" )
    public R updateById(@RequestBody ConfigMetadata configMetadata) {
        return R.ok(configMetadataService.updateById(configMetadata));
    }

    /**
     * 通过id删除
     * @param metadataId id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SysLog("通过id删除" )
    @DeleteMapping("/{metadataId}" )
    @PreAuthorize("@pms.hasPermission('gather_configmetadata_del')" )
    public R removeById(@PathVariable Long metadataId) {
        return R.ok(configMetadataService.removeById(metadataId));
    }

}
